/* beeb-palette.vala
 *
 * Copyright (C) 2010, 2011  Richard Talbot-Watkins
 * Copyright (C) 2010, 2011  Dave Jeffery
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Authors:
 *  Richard Talbot-Watkins <richtw1@gmail.com>
 * 	Dave Jeffery <david.richard.jeffery@gmail.com>
 */

/**
 * This class is the data model for the sprites.
 *
 * @author Richard Talbot-Watkins <richtw1@gmail.com>
 * @author Dave Jeffery <david.richard.jeffery@gmail.com>
 * @version 2011.0103
 * @since 0.1
 */
public class BeebSpriter.BeebPalette : GLib.Object {
	/* BBC Micro physical colour palette values. */
	public enum Colour {
		BLACK = 0,
		RED = 1,
		GREEN = 2,
		YELLOW = 3,
		BLUE = 4,
		MAGENTA = 5,
		CYAN = 6,
		WHITE = 7;

		/**
		 * Returns the next BBC Micro physical colour value.
		 *
		 * @return The next colour value, or cycle back to black.
		 */
		public Colour next () {
		    return (Colour) (((int) this + 1) & 7);
		}

		/**
		 * Returns the previous BBC Micro physical colour value.
		 *
		 * @return The previous colour value, or cycle forward to white.
		 */
		public Colour previous () {
		    return (Colour) (((int) this - 1) & 7);
		}

		/**
		 * Converts a Colour to an Rgba struct.
		 */
		public Rgba get_as_rgba () {
			switch (this) {
				case BLACK: return Rgba (0, 0, 0, 255);
				case RED: return Rgba (255, 0, 0, 255);
				case GREEN: return Rgba (0, 255, 0, 255);
				case YELLOW: return Rgba (255, 255, 0, 255);
				case BLUE: return Rgba (0, 0, 255, 255);
				case MAGENTA: return Rgba (255, 0, 255, 255);
				case CYAN: return Rgba (0, 255, 255, 255);
				case WHITE: return Rgba (255, 255, 255, 255);
				default: return Rgba (0, 0, 0, 0);
			}
		}

		/**
		 * Standard to_string function.
		 *
		 * @return The .bspr XML colour name for the layout.
		 */
		public string to_string () {
			switch (this) {
				case BLACK: return "Black";
				case RED: return "Red";
				case GREEN: return "Green";
				case YELLOW: return "Yellow";
				case BLUE: return "Blue";
				case MAGENTA: return "Magenta";
				case CYAN: return "Cyan";
				case WHITE: return "White";
				default: return "Unknown";
			}
		}
	}
}
